package chat;

import file.FileTransfer;
import ipconfig.Ipconfig;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.ScrollBarUI;

import main.Main;
import voSetting.ChattingVO;
import voSetting.SetMyInfoVO;
import custom.tree.EmployeesSearch;


public class Chatting extends JFrame implements Runnable{
	
// <1. field Variables> (필드변수) 
	// 1-1. for Frame View  (프레임 구성) 
	boolean maximum = false;
	Point point = new Point();  
	boolean resizing = false; 
	Ipconfig ip = new Ipconfig();
	boolean resizeFlag = true;
	boolean menuview = true;	// 1) on-off menu (메뉴 온오프) 
	boolean onTop = false;		// 2) set Always on the Top (언제나 위)
	EmployeesSearch em_f;	// 2) EmployeesSearch frame (직원찾기 프레임 객체) 
	FileTransfer file_f;		// 3) FileTransfer frame	(파일전송 프레임 객체) 
	Main main;
	
	ChatServer chatServer;
	Socket socket;
	Vector <String> v_chatter = new Vector<String>();	// 4) ChatterList Vector (채팅접속자 명단 벡터) - id
	static DefaultListModel<String> dl_chatter = new DefaultListModel(); // 5)ChatterList (채팅접속자 명단 리스트) - name
	
	Point initialClick;
	int pX, pY;
	
	// 1-2. for Chatting Process 채팅 처리
	ChattingVO chattingVo;	
	SetMyInfoVO setMyInfoVO;
	String m_id = "thd1123";		// 0) set my m_id
	String e_name = "홍길동";
	String e_position = "대리";
	int port = 0;
	
	//int tempCnt =1;			// 1) 
	
	OutputStream os;			// 2) Stream for DataOut (데이터 출력을 위한 스트림.)  
	ObjectOutputStream oos;					
													
	ChatClientThread clientThread; 		// 3) ChatClientThread (객체 선언) 
	
	
	private static JPanel contentPane;
	public static JLabel lb_name_to;
	public JScrollPane scrollPane;
	private JPanel south;
	JTextField textField;
	private JButton btnNewButton_7;
	private JPanel north;
	private JPanel panel;
	JTextPane textPane;
	JPanel pane_conversation;
	private JPanel panel_4;
	private JPanel panel_2;
	private JPanel panel_5;
	private JMenuBar menuBar;
	private JMenu mnNewMenu;
	private JMenuItem mntmNewMenuItem;
	private JMenuItem mntmNewMenuItem_1;
	private JMenuItem mntmNewMenuItem_2;
	private JMenuItem mntmNewMenuItem_3;
	private JMenuItem mntmNewMenuItem_4;
	private JMenuItem mntmNewMenuItem_5;
	private JSeparator separator;
	private JSeparator separator_1;
	private JSeparator separator_2;
	private JLabel lblAllRightsReserved;
	private JPanel panel_1;
	private JLabel lblNewLabel_2;
	private JButton button;
	private JButton button_1;
	private JButton button_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Chatting frame = new Chatting();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public Chatting(int port_number, Main main){
		this.port = port_number;
		this.main = main;
		setTitle("채팅방을 생성중입니다.");
		setUndecorated(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 300, 550);
		setMinimumSize(new Dimension(300, 550));			
		contentPane = new JPanel();
		contentPane.setBackground(new Color(152,191,218));
		contentPane.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.add(getPanel_2(), BorderLayout.CENTER);
		
		m_id = this.main.getClientThread().getSmvo().getM_id();
	    e_name = this.main.getClientThread().getSmvo().getE_name();
	    e_position = this.main.getClientThread().getSmvo().getE_position();
	    
	    System.out.println("----- 상태 정보 -----");
	    System.out.println("내 m_id : " + m_id);
	    System.out.println("내 e_name : " + e_name);
	    System.out.println("내 e_position : " + e_position);
	    
		try {											
			System.out.println("Chatting 포트번호" + port);

			System.out.println("서버측에 접속을 시도합니다." );
			socket = new Socket(ip.getFIXED_IP(), port);								
			
			System.out.println("클라이언트 스레드를 생성 및 실행합니다.");
			clientThread = new ChatClientThread(Chatting.this, socket); // 클라이언트에서 start를 함. 
			//System.out.println("Chatting try문으로 들어옴. 소켓 생성." );//실행 
			while(clientThread.oos == null){			// 1milliseconds 단위로 실행시킴 
				clientThread.join(1);
			}				
			connect();		// 콘넥트 메소드를 부름. 
			//clientThread.oos.flush();
			
			this.setVisible(true);
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.println("채팅창에서 서버연결에 실패했습니다.");
		}

		addWindowListener(new WindowAdapter() {
			public void windowClosed(WindowEvent e) {
				disconnect();
			};
			
			/*@Override
			public void windowClosing(WindowEvent e) {
					disconnect();
				}*/
			
		});
		
		addMouseListener(new MouseAdapter() {  
		      public void mousePressed(MouseEvent e) {  
		        resizing = getCursor().equals(Cursor.getDefaultCursor())? false:true;  
		        if(!e.isMetaDown()){  
		          point.x = e.getX();  
		          point.y = e.getY();  
		        }  
		      }  
		    });  
		addMouseMotionListener(new MouseMotionAdapter() {  
		      public void mouseDragged(MouseEvent e) {  
		        if(resizing){  
		          Point pt = e.getPoint(); 
		          setSize(getWidth()+pt.x - point.x, getHeight()+pt.y-point.y);  
		          point.x = pt.x;  
		          point.y = pt.y;
		        }  
		        else if(!e.isMetaDown()){  
		        Point p = getLocation();  
		        setLocation(p.x + e.getX() - point.x,  
		            p.y + e.getY() - point.y);  
		        }  
		      }  
		      public void mouseMoved(MouseEvent me){  
		        Point cursorLocation = me.getPoint();  
		        int xPos = cursorLocation.x;  
		        int yPos = cursorLocation.y;  
		        if(xPos < 5) setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));  
		        else if(xPos > getContentPane().getWidth()-5) setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));  
		        else if(yPos < 5) setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));  
		        else if(yPos > getContentPane().getHeight()-5) setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));  
		        else if(getCursor().equals(Cursor.getDefaultCursor()) == false) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
		      }  
		    });
		   
		
		
	}
// <2. Constructor> (생성자) 	
	public Chatting() {
		setUndecorated(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		setBounds(100, 100, 300, 550);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(152,191,218));
		contentPane.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setContentPane(contentPane);
		setMinimumSize(new Dimension(300, 550));
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.add(getPanel_2(), BorderLayout.CENTER);
		
	
		
	// 2-1. Make a Socket and start the thread (연결이 되면, 소켓을 만든다.) 																		
		try {											
			//chatServer = new ChatServer();						//우선 자동적으로 서버를 실행시켜줌. (나중에 중간서버에서 실행시킴) 
			InetAddress ia = InetAddress.getLocalHost();
			socket = new Socket(ip.getFIXED_IP(), port);								
			clientThread = new ChatClientThread(Chatting.this, socket); // 클라이언트에서 start를 함. 
			
			while(clientThread.oos == null){			// 1milliseconds 단위로 실행시킴 
				clientThread.join(1);
			}				
			connect();		// 콘넥트 메소드를 부름. 
			//initData();
			/*clientThread.oos.writeObject(chattingVo);								
			clientThread.oos.flush();*/
			
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.println("채팅창에서 서버연결에 실패했습니다.");
		}
		
		addMouseListener(new MouseAdapter() {  
		      public void mousePressed(MouseEvent e) {  
		        resizing = getCursor().equals(Cursor.getDefaultCursor())? false:true;  
		        if(!e.isMetaDown()){  
		          point.x = e.getX();  
		          point.y = e.getY();  
		        }  
		      }  
		    });  
		addMouseMotionListener(new MouseMotionAdapter() {  
		      public void mouseDragged(MouseEvent e) {  
		        if(resizing){  
		          Point pt = e.getPoint(); 
		          setSize(getWidth()+pt.x - point.x, getHeight()+pt.y-point.y);  
		          point.x = pt.x;  
		          point.y = pt.y;
		        }  
		        else if(!e.isMetaDown()){  
		        Point p = getLocation();  
		        setLocation(p.x + e.getX() - point.x,  
		            p.y + e.getY() - point.y);  
		        }  
		      }  
		      public void mouseMoved(MouseEvent me){  
		        Point cursorLocation = me.getPoint();  
		        int xPos = cursorLocation.x;  
		        int yPos = cursorLocation.y;  
		        if(xPos < 5) setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));  
		        else if(xPos > getContentPane().getWidth()-5) setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));  
		        else if(yPos < 5) setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));  
		        else if(yPos > getContentPane().getHeight()-5) setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));  
		        else if(getCursor().equals(Cursor.getDefaultCursor()) == false) setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));  
		      }  
		    });
	}
	
	
	
	
	
	// 2-3. run (런 메소드) : do nothing (아무 처리도 안 함) 
	@Override
	public void run() {			
		try {			
		} catch (Exception e) {
		}		
	}
	
// <3. Chatting List> get the chatting list and name  (채팅 명단(이름)과 아이디를 받아옴) 
/*	public void setV_chatter(Vector v_mid){	// 3-1. set id to Vector from main and EmployeeSearch (받아온 채팅 id를 벡터에 넣음) 
		Iterator<String> id = v_mid.iterator();
		while(id.hasNext()){
			String m_id = id.next();
			v_chatter.add(m_id);			
		}	
		for(int i=0; i<v_chatter.size(); i++){
			System.out.println("채팅벡터에서 들어간 접속자 id " +i+"번째 : " + v_chatter.get(i));			
		}
		
	}*/
	// 3-2. set name to List from main and EmployeeSearch (받아온 채팅명단(이름을 리스트에 뿌려줌)
/*	public static void listset(Vector v_name){			
		// list_chat.setListData(v_chatter);
		Iterator<String> it = v_name.iterator();
		while(it.hasNext()){
			String i_name = it.next();
			dl_chatter.addElement(i_name);			
		}	
    	for(int i=0; i<v_name.size(); i++){
			System.out.println("채팅리스트에서 들어간 접속자 이름 " +i+"번째 : " +dl_chatter.getElementAt(i));			
		}
		contentPane.updateUI();
	}*/
	
// <4. Command> 
	// 4-1. Case 1 : Connect (접속 메소드)  
	public void connect() throws IOException{
		System.out.println("현재 위치 connect() // 최초 데이터를 전송시킵니다.");
		chattingVo = new ChattingVO();
		chattingVo.setCommand(chattingVo.CONNECT);
		//System.out.println("2. Chatting 창에서 connection성공");//실행 
		chattingVo.setM_id(m_id);				
		chattingVo.setE_name(e_name);
		chattingVo.setE_position(e_position);			
		System.out.println("chattingVo.setM_id(m_id) 에 셋팅된 값 : " + chattingVo.getM_id());
		System.out.println("chattingVo.setE_name(e_name) 에 셋팅된 값 : " + chattingVo.getE_name());
		System.out.println("chattingVo.setE_position(e_position) 에 셋팅된 값 : " + chattingVo.getE_position());
		//chattingVo.setMessage("채팅이 시작되었습니다.");//실행 
		//System.out.println("3. 데이터 m_id  들어감" + m_id); //실행 
		clientThread.oos.writeObject(chattingVo);
		clientThread.oos.flush();
		System.out.println("보내기 완료");
		//System.out.println("4. Chatting 창에서 writeObject를 하였소");//실행 
		
	}
	
	// 4-2. Case 2 : DisConnect (접속해제 메소드)	
	public void disconnect(){			
		chattingVo = new ChattingVO();
		chattingVo.setM_id(m_id);				
		chattingVo.setE_name(e_name);
		chattingVo.setE_position(e_position);
		chattingVo.setMessage(e_name + "님의 접속이 끊어졌습니다."); 
		chattingVo.setCommand(chattingVo.DISCONNECT);
		System.out.println("접속해제 시도1");
		try{
			clientThread.oos.writeObject(chattingVo);
			clientThread.oos.flush();
			System.out.println("접속해제 시도2");
			
		} catch (Exception ex) {
			ex.printStackTrace();
		}		
	}
	
	// 4-3. Case 3 : Message (메시지 메소드)
	public void sendMsg(){										
		chattingVo = new ChattingVO();						
		chattingVo.setCommand(chattingVo.MESSAGE);				
		chattingVo.setM_id(m_id);				
		chattingVo.setE_name(e_name);
		chattingVo.setE_position(e_position);
		chattingVo.setMessage(textField.getText());
		try{
			clientThread.oos.writeObject(chattingVo);
			clientThread.oos.flush();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
	}
	
	// 4-4. Case 4 : Invite (초대 메소드)	
	public void inviteEmployees(){
		FileDialog nameBox;
        nameBox = new FileDialog(this, "대화내용 저장", FileDialog.SAVE);
        nameBox.setVisible(true);
        String fileDirectory = nameBox.getDirectory();
        String savename = nameBox.getFile();
        savename = fileDirectory.concat(savename);
 
        try (PrintWriter pWriter = new PrintWriter(new FileWriter(savename))) {
            pWriter.println(textPane);
        } catch (IOException ex) {
            Logger.getLogger(Chatting.class.getName()).log(Level.SEVERE, null, ex);
        }
	
	}

// 저장 
	public void save(){	
		 try{
			 FileWriter out = new FileWriter(e_name+"" +".txt");
	            out.write(textPane.getText());
	            out.close();	         
	      } catch (Exception f) {
	      	 f.printStackTrace();
	      }
		 	
		/*FileOutputStream fos = null;
		OutputStreamWriter osw = null;
		BufferedWriter bw = null;
		try{
			fos = new FileOutputStream(e_name+"" +".txt");
			osw = new OutputStreamWriter(fos);
			bw = new BufferedWriter(osw);
			bw.write(textPane.getText());
			bw.flush();
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			try{
				bw.close();
				osw.close();
				fos.close();
			}catch(Exception ex2){}
		} */
	}
	
// <5. Frame Component> (프레임 요소) 	
	private JLabel getLb_name_to() {
		if (lb_name_to == null) {
			lb_name_to = new JLabel("채팅방을 생성중입니다.");
			lb_name_to.setForeground(Color.DARK_GRAY);
			lb_name_to.setBorder(new EmptyBorder(5, 5, 5, 5));
			lb_name_to.setFont(new Font("맑은 고딕", Font.PLAIN, 14));
		}
		return lb_name_to;
	}
	JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBorder(null);
			scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			scrollPane.setViewportView(getTextPane());
		}
		return scrollPane;
	}
	private JPanel getSouth() {
		if (south == null) {
			south = new JPanel();
			south.setBackground(new Color(152,191,218));
			south.setLayout(new BorderLayout(0, 0));
			south.add(getBtnNewButton_7(), BorderLayout.EAST);
			south.add(getTextField(), BorderLayout.CENTER);
			south.add(getLblAllRightsReserved(), BorderLayout.SOUTH);
			south.add(getPanel_1(), BorderLayout.NORTH);
		}
		return south;
	}
	JTextField getTextField() {
		if (textField == null) {
			textField = new JTextField();
			textField.addKeyListener(new KeyAdapter() {
				@Override
				public void keyReleased(KeyEvent e) {
					if(e.getKeyCode() == KeyEvent.VK_ENTER){
						sendMsg();
						textField.setText("");
					}
				}
			});
			textField.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			textField.setColumns(10);
		}
		return textField;
	}
	private JButton getBtnNewButton_7() {
		if (btnNewButton_7 == null) {
			btnNewButton_7 = new JButton("대화 전송");
			btnNewButton_7.setBackground(new Color(255, 255, 255));
			btnNewButton_7.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					 sendMsg();
					 textField.setText("");
				}
			});
			btnNewButton_7.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return btnNewButton_7;
	}
	private JPanel getPanel_1_1() {
		if (north == null) {
			north = new JPanel();
			north.setBackground(new Color(152,191,218));
			north.setLayout(new BorderLayout(0, 0));
			north.add(getLb_name_to(), BorderLayout.WEST);
			north.add(getPanel_4(), BorderLayout.EAST);
			north.add(getPanel_2_2(), BorderLayout.SOUTH);
		}
		return north;
	}
	private JPanel getPanel_2() {
		if (panel == null) {
			panel = new JPanel();
			panel.setBackground(new Color(0, 153, 51));
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getSouth(), BorderLayout.SOUTH);
			panel.add(getPanel_1_1(), BorderLayout.NORTH);
			panel.add(getPanel_2_1(), BorderLayout.CENTER);
/*			
			
			addMouseListener(new MouseAdapter() {
		        public void mousePressed(MouseEvent e) {
		            initialClick = e.getPoint();
		            getComponentAt(initialClick);
		        }
		    });

		    addMouseMotionListener(new MouseMotionAdapter() {
		        @Override
		        public void mouseDragged(MouseEvent e) {

		            // get location of Window
		            int thisX = getLocation().x;
		            int thisY = getLocation().y;

		            // Determine how much the mouse moved since the initial click
		            int xMoved = (thisX + e.getX()) - (thisX + initialClick.x);
		            int yMoved = (thisY + e.getY()) - (thisY + initialClick.y);

		            // Move window to this position
		            int X = thisX + xMoved;
		            int Y = thisY + yMoved;
		            setLocation(X, Y);
		        }
		    });	 */   
		}
		return panel;
	}
	private JTextPane getTextPane() {
		if (textPane == null) {
			textPane = new JTextPane();
			textPane.setEditable(false);
			textPane.setBackground(new Color(255, 255, 255));
			textPane.setBorder(new EmptyBorder(5, 5, 0, 5));
			textPane.setContentType("text/html");
			textPane.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
			textPane.setMinimumSize(new Dimension(300,500));
		}
		return textPane;
	}

	public static void setLb_name_to(String string) {
		lb_name_to.setText(string);
		
	}

	
	JPanel getPanel_2_1() {
		if (pane_conversation == null) {
			pane_conversation = new JPanel();
			pane_conversation.setBackground(new Color(255, 255, 255));
			pane_conversation.setBorder(new EmptyBorder(5, 5, 5, 5));
			pane_conversation.setLayout(new BorderLayout(0, 0));
			pane_conversation.add(getScrollPane(), BorderLayout.CENTER);
		}
		return pane_conversation;
	}

	public String getM_id() {
	      return m_id;
	   }

	   public void setM_id(String m_id) {
	      this.m_id = m_id;
	   }

	   public String getE_name() {
	      return e_name;
	   }

	   public void setE_name(String e_name) {
	      this.e_name = e_name;
	   }

	   public String getE_position() {
	      return e_position;
	   }

	   public void setE_position(String e_position) {
	      this.e_position = e_position;
	   }

	   public int getPort() {
	      return port;
	   }

	   public void setPort(int port) {
	      this.port = port;
	   }

	   public ChatClientThread getClientThread() {
	      return clientThread;
	   }

	   public void setClientThread(ChatClientThread clientThread) {
	      this.clientThread = clientThread;
	   }
	private JPanel getPanel_4() {
		if (panel_4 == null) {
			panel_4 = new JPanel();
			panel_4.setAlignmentY(0.0f);
			panel_4.setAlignmentX(0.0f);
			panel_4.setOpaque(false);
			panel_4.setBackground(new Color(152,191,218));
			panel_4.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
			panel_4.add(getButton());
			panel_4.add(getButton_1());
			panel_4.add(getButton_2());
		}
		return panel_4;
	}
	private JPanel getPanel_2_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setBorder(new EmptyBorder(10, 5, 5, 5));
			panel_2.setOpaque(false);
			panel_2.setBackground(new Color(152,191,218));
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getPanel_5(), BorderLayout.WEST);
			panel_2.add(getLblNewLabel_2(), BorderLayout.EAST);
		}
		return panel_2;
	}
	private static void addPopup(Component component, final JPopupMenu popup) {
	}
	private JPanel getPanel_5() {
		if (panel_5 == null) {
			panel_5 = new JPanel();
			panel_5.setOpaque(false);
			panel_5.setBackground(new Color(0, 153, 51));
			panel_5.setLayout(new BorderLayout(0, 0));
			panel_5.add(getMenuBar_1());
		}
		return panel_5;
	}
	private JMenuBar getMenuBar_1() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.setBorder(null);
			menuBar.add(getMnNewMenu());
		}
		return menuBar;
	}
	private JMenu getMnNewMenu() {
		if (mnNewMenu == null) {
			mnNewMenu = new JMenu("MENU");
			mnNewMenu.setForeground(Color.DARK_GRAY);
			mnNewMenu.setBackground(new Color(152,191,218));
			mnNewMenu.setBorder(null);
			mnNewMenu.setOpaque(true);
			mnNewMenu.setFont(new Font("맑은 고딕", Font.BOLD, 12));
			mnNewMenu.add(getMntmNewMenuItem_2());
			mnNewMenu.add(getSeparator());
			mnNewMenu.add(getMntmNewMenuItem_4());
			mnNewMenu.add(getMntmNewMenuItem_5());
			mnNewMenu.add(getSeparator_1());
			mnNewMenu.add(getMntmNewMenuItem_3());
			mnNewMenu.add(getMntmNewMenuItem_1());
			mnNewMenu.add(getSeparator_2());
			mnNewMenu.add(getMntmNewMenuItem());
		}
		return mnNewMenu;
	}
	private JMenuItem getMntmNewMenuItem() {
		if (mntmNewMenuItem == null) {
			mntmNewMenuItem = new JMenuItem("대화창 나가기");
			mntmNewMenuItem.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			mntmNewMenuItem.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem;
	}
	private JMenuItem getMntmNewMenuItem_1() {
		if (mntmNewMenuItem_1 == null) {
			mntmNewMenuItem_1 = new JMenuItem("쪽지 전송");
			mntmNewMenuItem_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
			});
			mntmNewMenuItem_1.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem_1;
	}
	private JMenuItem getMntmNewMenuItem_2() {
		if (mntmNewMenuItem_2 == null) {
			mntmNewMenuItem_2 = new JMenuItem("항상 맨 위");
			mntmNewMenuItem_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(!onTop){
						setAlwaysOnTop(true);
						mntmNewMenuItem_2.setText("항상 맨위 해제");						
						onTop=true;
					}else{
						setAlwaysOnTop(false);
						mntmNewMenuItem_2.setText("항상 맨 위");							
						onTop=false;
					}	
				}
			});
			mntmNewMenuItem_2.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem_2;
	}
	private JMenuItem getMntmNewMenuItem_3() {
		if (mntmNewMenuItem_3 == null) {
			mntmNewMenuItem_3 = new JMenuItem("파일 전송");
			mntmNewMenuItem_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					file_f = new FileTransfer();
					file_f.lb_name_to.setText(v_chatter.firstElement()+"외 총 "+ v_chatter.size()+"명");
					file_f.setV_filer(v_chatter);
					file_f.setVisible(true);
				}
			});
			mntmNewMenuItem_3.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem_3;
	}
	private JMenuItem getMntmNewMenuItem_4() {
		if (mntmNewMenuItem_4 == null) {
			mntmNewMenuItem_4 = new JMenuItem("대화상대 추가 ");
			mntmNewMenuItem_4.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					int nowX = getLocation().x;
					int nowY = getLocation().y;
					int nowWidth = getWidth();
					int nowheigh = getHeight();
					em_f = new EmployeesSearch();
					em_f.addEmployeeFrame(2, Chatting.this);
					em_f.setBounds(nowX+nowWidth, nowY+nowheigh/3, 200, nowheigh/3*2);
					em_f.setVisible(true);	
				}
			});
			mntmNewMenuItem_4.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem_4;
	}
	private JMenuItem getMntmNewMenuItem_5() {
		if (mntmNewMenuItem_5 == null) {
			mntmNewMenuItem_5 = new JMenuItem("대화내용 저장");
			mntmNewMenuItem_5.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					int Choice = JOptionPane.showConfirmDialog(Chatting.this, "현재까지 대화내용을 저장하시겠습니까? ", "대화내용 저장", 2);
					if(Choice==JOptionPane.OK_OPTION){ 
					//save();
					}else{
						
					}
				}
			});
			mntmNewMenuItem_5.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return mntmNewMenuItem_5;
	}
	private JSeparator getSeparator() {
		if (separator == null) {
			separator = new JSeparator();
		}
		return separator;
	}
	private JSeparator getSeparator_1() {
		if (separator_1 == null) {
			separator_1 = new JSeparator();
		}
		return separator_1;
	}
	private JSeparator getSeparator_2() {
		if (separator_2 == null) {
			separator_2 = new JSeparator();
		}
		return separator_2;
	}
	private JLabel getLblAllRightsReserved() {
		if (lblAllRightsReserved == null) {
			lblAllRightsReserved = new JLabel("All Rights Reserved Copyrightⓒ 2015 MINO Corp");
			lblAllRightsReserved.setBackground(new Color(152,191,218));
			lblAllRightsReserved.setHorizontalAlignment(SwingConstants.TRAILING);
			lblAllRightsReserved.setFont(new Font("맑은 고딕", Font.PLAIN, 10));
		}
		return lblAllRightsReserved;
	}
	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setBackground(new Color(176, 224, 230));
			panel_1.setLayout(new BorderLayout(0, 0));
		}
		return panel_1;
	}
	private JLabel getLblNewLabel_2() {
		if (lblNewLabel_2 == null) {
			lblNewLabel_2 = new JLabel("대화명단");
			lblNewLabel_2.setForeground(Color.DARK_GRAY);
			lblNewLabel_2.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent e) {
					int nowX = getLocation().x;
					int nowY = getLocation().y;
					int nowWidth = getWidth();
					int nowheigh = getHeight();
					ChatList ct = new ChatList(dl_chatter);
					ct.setBounds(nowX+nowWidth, nowY, 150, nowheigh/3);					
					ct.setVisible(true);
				}
			});
			lblNewLabel_2.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		}
		return lblNewLabel_2;
	}
	private JButton getButton() {
		if (button == null) {
			button = new JButton("");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					setState(JFrame.ICONIFIED);	
				}
			});
			button.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\minimum.png"));
			button.setBorder(null);
			button.setBackground(new Color(152,191,218));
		}
		return button;
	}
	private JButton getButton_1() {
		if (button_1 == null) {
			button_1 = new JButton("");
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if(maximum !=true){
						setExtendedState(JFrame.MAXIMIZED_BOTH);	
						button_1.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\initsize.png"));
						maximum = true;
					}else{
						setBounds(100, 100, 300, 550);
						button_1.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\maximum.png"));
						maximum = false;
					}
					
				}
			});
			button_1.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\maximum.png"));
			button_1.setBorder(null);
			button_1.setBackground(new Color(152,191,218));
		}
		return button_1;
	}
	private JButton getButton_2() {
		if (button_2 == null) {
			button_2 = new JButton("");
			button_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
				}
			});
			button_2.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\close.png"));
			button_2.setBorder(null);
			button_2.setBackground(new Color(152,191,218));
		}
		return button_2;
	}
}
